package com.lc.YYGH.hosp.controller.api;


import com.lc.YYGH.common.result.Result;
import com.lc.YYGH.hosp.service.DepartmentService;
import com.lc.YYGH.hosp.service.HospitalService;
import com.lc.YYGH.hosp.service.HospitalSetService;
import com.lc.YYGH.hosp.service.ScheduleService;
import com.lc.YYGH.model.hosp.Hospital;
import com.lc.YYGH.model.hosp.Schedule;
import com.lc.YYGH.vo.hosp.HospitalQueryVo;
import com.lc.YYGH.vo.hosp.ScheduleOrderVo;
import com.lc.YYGH.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags="医院管理接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {
    @Autowired
    private  HospitalService hospitalService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private HospitalSetService hospitalSetService;
    @ApiOperation(value="获取分页列表")
    @GetMapping("{page}/{limit}")
    public Result index
            (
                    @ApiParam(name="page",value="当前页码",required = true)
                    @PathVariable Integer page,
                    @ApiParam(name="limit",value="每页记录数",required = true)
                    @PathVariable Integer limit,
                    @ApiParam(name="hospitalQueryVo",value="查询对象",required = false)
                    HospitalQueryVo hospitalQueryVo)
    {
        Page<Hospital> pageModel=hospitalService.selectPage(page,limit,hospitalQueryVo);
        return Result.success(pageModel);
    }


    @ApiOperation(value="根据医院名称获取医院列表")
    @GetMapping("findByHosname/{hosname}")
    public Result findByhosname(
        @ApiParam(name="hosname",value="医院名称",required = true)
        @PathVariable String hosname)
    {
        List<Hospital> list=hospitalService.findByHosname(hosname);
        return Result.success(list);
    }

    @ApiOperation(value ="获取科室列表")
    @GetMapping("department/{hoscode}")
    public Result index(
            @ApiParam(name="hoscode",value="医院code",required=true)
            @PathVariable String hoscode)
    {
      return Result.success(departmentService.findDepTree(hoscode));
    }
    @ApiOperation(value="医院预约挂号详情")
    @GetMapping("{hoscode}")
    public Result item(
            @ApiParam(name="hoscode",value="医院code",required=true)
            @PathVariable String hoscode)
    {
        return Result.success(hospitalService.item(hoscode));
    }

    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode) {
        return Result.success(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }

    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate) {
        return Result.success(scheduleService.getDetailSchedule(hoscode, depcode, workDate));
    }

    @ApiOperation(value = "获取排班id获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId) {
        Schedule schedule = scheduleService.getScheduleId(scheduleId);
        return Result.success(schedule);
    }

    @ApiOperation(value="根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @ApiParam(name="scheduleId", value="排班id",required=true)
            @PathVariable("scheduleId")String scheduleId){
        ScheduleOrderVo scheduleOrderVo = scheduleService.getScheduleOrderVo(scheduleId);
        return scheduleOrderVo;
    }

    @ApiOperation(value="获取医院签名")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(
            @ApiParam(name="hoscode",value="医院code",required=true)
            @PathVariable("hoscode") String hoscode)
    {
        return hospitalSetService.getSignInfoVo(hoscode);
    }

}
